/*公用js*/
var domain = "http://localhost:8077"; //默认空则直接本站根目录
domain = "https://localhost:44376/api";

//根据value查询到数组里第一个title
function getTitleByValue(arr,value) {
    //console.log("debug query value:"+value);
    //console.log(arr);
    var result="";
    for(var i=0;i<arr.length;i++){
        var v=arr[i];
        if(v.value==value){
            result= v.title;
            break;
        }
    }
    return result;
}

//把form里的表单构造成key/value数组
function getFormData($form) {
    var unindexed_array = $form.serializeArray();
    var indexed_array = {};

    $.map(unindexed_array, function (n, i) {
        indexed_array[n['name']] = n['value'];
    });
    return indexed_array;
}

//反序列化
function unserialize(url) {
    if (url.indexOf("?") > -1) {
        url = url.substring(1);
    }
    var parts = url.split("&");
    var json = {};
    parts.forEach(function (item) {
        if (item.indexOf("=") > -1) {
            var itemArray = item.split("=");
            json[itemArray[0]] = itemArray[1];
        }
    });
    return json;
}

//ajax调用错误时候回调
function ajaxError(ret,doc) {
    console.log("ajax返回错误：" + ret.status)

    //console.log(decodeURIComponent(doc[0].data));
    //console.log(decodeURIComponent(doc[0].url));
    alert("接口访问错误:" + ret.status);
}

//ajax调用成功时候回调
function ajaxSuccess(ret,doc) {
    console.log("ajax读取成功：")
    console.log(ret);
}